//
// Description: 5882. 网格游戏
// Created by Loading on 2021/9/27.
//

#include <bits/stdc++.h>

using namespace std;

long long gridGame(vector<vector<int>> &grid) {
    int n = grid[0].size();

    // 前缀和
    vector<vector<long long>> sum(2, vector<long long>(n));

    sum[0][0] = grid[0][0];
    sum[1][0] = grid[1][0];
    for (int i = 1; i < n; ++i) {
        sum[0][i] = sum[0][i - 1] + grid[0][i];
        sum[1][i] = sum[1][i - 1] + grid[1][i];
    }
    long long res = sum[0][n - 1] - sum[0][0];
    for (int i = 1; i < n; ++i) {
        // 机器人二只能在第一个格子或最后一个格子向下走，两条路径最大值中的最小值即为结果
        res = min(res, max(sum[0][n - 1] - sum[0][i], sum[1][i - 1]));
    }

    return res;
}

int main() {
    vector<vector<int>> grid = {{2, 5, 4},
                                {1, 5, 1}};
    long long res = gridGame(grid);
    cout << res << endl;

    return 0;
}